Solving 10385 - Duathlon (Ternary search)
[andmenj-acm.git] / 10018 - Reverse and add / 10018.cpp
blobdffb602ace77c878b5b0abceb42c7b284aedeb2a
1 /*
2 Problem: 10018 - Reverse and add
3 */
4 using namespace std;
5 #include <algorithm>
6 #include <iostream>
7 #include <iterator>
8 #include <sstream>
9 #include <fstream>
10 #include <cassert>
11 #include <climits>
12 #include <cstdlib>
13 #include <cstring>
14 #include <string>
15 #include <cstdio>
16 #include <vector>
17 #include <cmath>
18 #include <queue>
19 #include <deque>
20 #include <stack>
21 #include <list>
22 #include <map>
23 #include <set>
25 #define foreach(x, v) for (typeof (v).begin() x = (v).begin(); x != (v).end(); ++x)
26 #define For(i, a, b) for (int i=(a); i<(b); ++i)
27 #define D(x) cout << #x " is " << x << endl
29 typedef unsigned int uint;
31 uint invert(uint n){
32 uint p = 0;
33 while(n){
34 p = p * 10 + n % 10;
35 n = n / 10;
37 return p;
40 int main(){
41 uint t, n;
42 cin >> t;
43 while (t--){
44 cin >> n;
45 uint ans = 0;
46 while (n != invert(n)){
47 ans++;
48 n += invert(n);
50 cout << ans << " " << n << endl;
52 return 0;